package com.lagou;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author lxh
 * @date 2021/3/2
 */
public class SortNumberDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //获取配置信息，封装任务
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf,"sortNumberDriver");
        //设置jar加载路径
        job.setJarByClass(SortNumberDriver.class);
        //设置mapper
        job.setMapperClass(SortNumberMapper.class);
        //设置reducer
        job.setReducerClass(SortNumberReducer.class);
        //设置mapper输出的key
        job.setMapOutputKeyClass(LongWritable.class);
        //设置mapper输出的value
        job.setMapOutputValueClass(NullWritable.class);
        //设置reducer输出的key
        job.setOutputKeyClass(LongWritable.class);
        //设置reducer输出的value
        job.setOutputValueClass(LongWritable.class);
        //此处可以不写，默认为1，reduceTask数量默认与输出结果的文件数保持一致
        job.setNumReduceTasks(1);
        //读入三个文件所在的目录
        FileInputFormat.setInputPaths(job,"E:\\bigdata\\phase-i-module-1\\验证资料");
        //输出结果
        FileOutputFormat.setOutputPath(job,new Path("E:\\bigdata\\phase-i-module-1\\验证资料\\result"));
        //提交任务
        boolean result = job.waitForCompletion(true);

        System.exit(result?0:1);
    }
}
